﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Data.Common;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.ComponentModel;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using NetROS.Tiers.Data.Bases;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.SqlClient
{
    ///<summary>
    /// This class is the SqlClient Data Access Logic Component implementation for the <see cref="PutniNalog"/> entity.
    ///</summary>
    [DataObject]
    [CLSCompliant(true)]
    public partial class SqlPutniNalogProvider : SqlPutniNalogProviderBase
    {
        /// <summary>
        /// Creates a new <see cref="SqlPutniNalogProvider"/> instance.
        /// Uses connection string to connect to datasource.
        /// </summary>
        /// <param name="connectionString">The connection string to the database.</param>
        /// <param name="useStoredProcedure">A boolean value that indicates if we use the stored procedures or embedded queries.</param>
        /// <param name="providerInvariantName">Name of the invariant provider use by the DbProviderFactory.</param>
        public SqlPutniNalogProvider(string connectionString, bool useStoredProcedure, string providerInvariantName) : base(connectionString, useStoredProcedure, providerInvariantName) { }

        public override DataTable GetDistinctRelacijaOd(TransactionManager transactionManager)
        {

            SqlDatabase database = new SqlDatabase(ConnectionString);

            DbCommand command = database.GetSqlStringCommand("SELECT DISTINCT RelacijaOd FROM fin.tblPutniNalogStavkaPrijevoz");

            //Create Collection
            //  NetROS.Tiers.Entities.TList<PutniNalog> rows = new NetROS.Tiers.Entities.TList<PutniNalog>();\
            IDataReader reader = null;
            DataTable rows = new DataTable();
            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(command, "GetDistinctRelacijaOd"));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, command);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, command);
                }
                rows = NetROS.Tiers.Data.Utility.ConvertDataReaderToDataSet(reader).Tables[0];
                // Fill(reader, rows, 0, int.MaxValue);
                //int count = rows.Count;

                // if (reader.NextResult())
                // {
                //     if (reader.Read())
                //     {
                //         count = reader.GetInt32(0);
                //     }
                // }


                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(command, "GetDistinctRelacijaOd"));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                command = null;
            }
            return rows;
        }// end GetDistinctRelacijaOd


         public override DataTable GetDistinctRelacijaDo(TransactionManager transactionManager)
        {

            SqlDatabase database = new SqlDatabase(ConnectionString);

            DbCommand command = database.GetSqlStringCommand("SELECT DISTINCT RelacijaDo FROM fin.tblPutniNalogStavkaPrijevoz");

            //Create Collection
            //  NetROS.Tiers.Entities.TList<PutniNalog> rows = new NetROS.Tiers.Entities.TList<PutniNalog>();\
            IDataReader reader = null;
            DataTable rows = new DataTable();
            try
            {
                //Provider Data Requesting Command Event
                OnDataRequesting(new CommandEventArgs(command, "GetDistinctRelacijaDo"));

                if (transactionManager != null)
                {
                    reader = Utility.ExecuteReader(transactionManager, command);
                }
                else
                {
                    reader = Utility.ExecuteReader(database, command);
                }
                rows = NetROS.Tiers.Data.Utility.ConvertDataReaderToDataSet(reader).Tables[0];
                // Fill(reader, rows, 0, int.MaxValue);
                //int count = rows.Count;

                // if (reader.NextResult())
                // {
                //     if (reader.Read())
                //     {
                //         count = reader.GetInt32(0);
                //     }
                // }


                //Provider Data Requested Command Event
                OnDataRequested(new CommandEventArgs(command, "GetDistinctRelacijaDo"));
            }
            finally
            {
                if (reader != null)
                    reader.Close();

                command = null;
            }
            return rows;
        }// end GetDistinctRelacijaOd
    }
}